package com.lyrcsoft.application.config;

import com.lyrcsoft.service.OrderService;
import com.lyrcsoft.service.T1Service;
import com.lyrcsoft.service.T3Service;
import com.lyrcsoft.service.T9Service;
import org.springframework.beans.factory.annotation.Autowire;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Primary;
import org.springframework.context.event.EventListener;

/**
 * @author fujc-dev@qq.com
 * @date 2023/6/30 9:50
 */

@Configurable
@ComponentScan({"com.lyrcsoft","java.lyrcsoft"})
public class AppConfig {


	@Bean
	public String number() {
		return "注入一个String";
	}

	@Bean({"orderService", "orderService1", "orderService2"})
	public OrderService orderService() {
		return new OrderService();
	}

	@Bean({"test"})
	@Primary
	public OrderService test() {
		return new OrderService();
	}


	/**
	 * 以@Bean的方式注入，如果其中需要依赖注入的话：会取找setXxxx方法 // 其他Component的方法使用的是@Autowired、@Resource，@Value注解
	 */
	@Bean(autowire = Autowire.BY_TYPE)
	public T1Service t1Service() {
		return new T1Service();
	}

	@Bean(initMethod = "initMethod")
	public T3Service t3Service() {
		return new T3Service();
	}

	// 别名的存储：map => map<orderService1,orderService>
	//			 map => map<orderService2,orderService>

	@Bean
	public T9Service t9Service() {
		return new T9Service();
	}

	@EventListener
	public void doAny(ApplicationEvent event) {
		System.out.println("test listener");
	}

}
